540B - School Marks - CodeForces Solution


greedy implementation *1700

Please click on ads to support us..

C++ Code:

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int a[1000],b[1000];
int ans=0;
int main()
{
	int n,k,p,x,y,i,sum=0,summ=0;
	cin>>n>>k>>p>>x>>y;
	for(i=1;i<=k;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	sort(a+1,a+k+1);
	for(i=1;i<=k;i++)
	{
		if(a[i]<y)
		{
			ans++;
		}
	}
	if(ans<(n+1)/2)
	{
		for(i=k+1;i<=n;i++)
	   {
		    a[i]=1;
		    b[i]=a[i];
	   }
	   for(i=k+n/2-ans+1;i<=n;i++)
	   {
	    	a[i]=y;
		    b[i]=a[i];
       }
	}
	else
	    a[i]=-1;
	for(i=1;i<=n;i++)
	{
		summ+=a[i];
	}
	sort(a+1,a+n+1);
	if(a[n/2+1]<y||summ>x)
	    cout<<"-1"<<endl;
	else
	{
		for(i=k+1;i<n;i++)
		{
			cout<<b[i]<<" ";
		}
		cout<<b[n]<<endl;
	}
	return 0;
} 
    		 	 	  	 		 		   						


Comments

Submit
0 Comments
More Questions

550B - Preparing Olympiad
939B - Hamster Farm
732A - Buy a Shovel
1220C - Substring Game in the Lesson
452A - Eevee
1647B - Madoka and the Elegant Gift
1408A - Circle Coloring
766B - Mahmoud and a Triangle
1618C - Paint the Array
469A - I Wanna Be the Guy
1294A - Collecting Coins
1227A - Math Problem
349A - Cinema Line
47A - Triangular numbers
1516B - AGAGA XOOORRR
1515A - Phoenix and Gold
1515B - Phoenix and Puzzle
155A - I_love_username
49A - Sleuth
1541A - Pretty Permutations
1632C - Strange Test
673A - Bear and Game
276A - Lunch Rush
1205A - Almost Equal
1020B - Badge
1353A - Most Unstable Array
770A - New Password
1646B - Quality vs Quantity
80A - Panoramix's Prediction
1354B - Ternary String